﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data.SqlClient;
using System.Data;

namespace Acms.SqlDal
{
    public class SiteVersionDal : Base
    {
        public enum Fields
        {
            SiteId,
            Change
        }

        protected override void ReadRecord(Hashtable table, SqlDataReader reader)
        {
            GetReaderValue<int>(Fields.SiteId, reader, table);
            GetReaderValue<DateTime>(Fields.Change, reader, table);
        }

        public Hashtable[] GetAll(int siteId)
        {
            SqlCommand cmd = CreateCommand("GetAll");
            AddInputParameter(cmd, "SiteId", siteId, SqlDbType.Int);
            return ExecuteGetCollection(cmd);
        }

        public Hashtable[] GetAllFuture(int siteId)
        {
            SqlCommand cmd = CreateCommand("GetAllFuture");
            AddInputParameter(cmd, "SiteId", siteId, SqlDbType.Int);
            return ExecuteGetCollection(cmd);
        }

        public Hashtable[] GetRange(int siteId, DateTime? startDate, DateTime? endDate)
        {
            SqlCommand cmd = CreateCommand("GetRange");
            AddInputParameter(cmd, "StartDate", startDate, SqlDbType.DateTime);
            AddInputParameter(cmd, "SiteId", siteId, SqlDbType.Int);
            AddInputParameter(cmd, "EndDate", endDate, SqlDbType.DateTime);
            return ExecuteGetCollection(cmd);
        }


        public Hashtable GetCurrent(int siteId)
        {
            SqlCommand cmd = CreateCommand("GetCurrent");
            AddInputParameter(cmd, "SiteId", siteId, SqlDbType.Int);
            return ExecuteGetItem(cmd);
        }

        public Hashtable GetCurrentBySiteUrl(string siteUrl)
        {
            SqlCommand cmd = CreateCommand("GetCurrentBySiteUrl");
            AddInputParameter(cmd, "SiteUrl", siteUrl, SqlDbType.VarChar, 255);
            return ExecuteGetItem(cmd);
        }
    }
}
